home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / System / Common / h / floatmath < prev    next >
Text File  |  1997-01-14  |  4KB  |  118 lines

  1. /*
  2. * Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT 
  3. * NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject
  4. * to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in   
  5. * the file "Doc/License" of the Sather distribution.  The license is also  
  6. * available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.
  7. * -----> Please email comments to "sather-bugs@icsi.berkeley.edu". <-----
  8. */
  9.  
  10. /* Have we already been here? */
  11. #ifndef FLOATMATH
  12. #define FLOATMATH 1
  13. #include <float.h>
  14.  
  15. /* XPG-defined constants not supplied by MS Visual C++ include files */
  16. #if defined(WIN32) || defined(__riscos__)
  17. # define M_E        2.7182818284590452354
  18. # define M_LOG2E    1.4426950408889634074
  19. # define M_LOG10E   0.43429448190325182765
  20. # define M_LN2      0.69314718055994530942
  21. # define M_LN10     2.30258509299404568402
  22. # define M_PI       3.14159265358979323846
  23. # define M_PI_2     1.57079632679489661923
  24. # define M_PI_4     0.78539816339744830962
  25. # define M_1_PI     0.31830988618379067154
  26. # define M_2_PI     0.63661977236758134308
  27. # define M_2_SQRTPI 1.12837916709551257390
  28. # define M_SQRT2    1.41421356237309504880
  29. # define M_SQRT1_2  0.70710678118654752440
  30. #endif
  31.  
  32. #ifdef SUNOS5
  33. double signaling_nan(int);
  34. double infinity();
  35. #endif
  36.  
  37. /*
  38. * This file is included by Sather/System/header.h
  39. * at the head of each compiler-generated header file.
  40. *
  41. * If the system supports single-precision library calls, these are used.
  42. * Otherwise the floats are converted to double and back afterwards.
  43. */
  44.  
  45. #if defined(ASSIGNFLOAT)
  46. /* WITH single-precision library */
  47.  
  48. #if defined(SPARC) && defined (SUNOS4)
  49.  
  50. /* Fix a problem in the <math.h> in SunOS 4 on the Sparc.
  51.  * This otherwise causes annoying warning messages during compiling.
  52.  * If you have problems with this redefinition, delete it and ignore
  53.  * the warning messages.
  54.  *
  55.  * This is how the original definition should look like:
  56.  * #define    ASSIGNFLOAT(x,y)    { union {double _d; float _f } _kluge; _kluge._d = (y); x = _kluge._f; }
  57.  */
  58.  
  59. #undef ASSIGNFLOAT
  60. #define    ASSIGNFLOAT(x,y)    { union {double _d; float _f;} _kluge; _kluge._d = (y); x = _kluge._f; }
  61.  
  62. #endif    /* defined(SPARC) && defined (SUNOS4) */
  63.  
  64. #define _FM_F(name)    \
  65.     static FLT r_##name()\
  66.     {float f; ASSIGNFLOAT(f,r_##name##_()); return f;}
  67.  
  68. #define _FM_F_I(name)    \
  69.     static FLT r_##name(INT i)\
  70.     {float f; ASSIGNFLOAT(f,r_##name##_(&i)); return f;}
  71.  
  72. #define _FM_F_F(name)    \
  73.     static FLT r_##name(FLT f)\
  74.     {ASSIGNFLOAT(f,r_##name##_(&f)); return f;}
  75.  
  76. #define _FM_F_FF(name)    \
  77.     static FLT r_##name(FLT f,FLT g)\
  78.     {ASSIGNFLOAT(f,r_##name##_(&f,&g)); return f;}
  79.  
  80. #define _FM_F_FI(name)    \
  81.     static FLT r_##name(FLT f,INT i)\
  82.     {ASSIGNFLOAT(f,r_##name##_(&f,&i)); return f;}
  83.  
  84. #define _FM_F_IF(name)    \
  85.     static FLT r_##name(INT i,FLT f)\
  86.     {ASSIGNFLOAT(f,r_##name##_(&i,&f)); return f;}
  87.  
  88. #define _FM_B_F(name)    \
  89.     static BOOL ir_##name(FLT f)\
  90.     {return ir_##name##_(&f);}
  91.  
  92. #define _FM_I_F(name)    \
  93.     static INT ir_##name(FLT f)\
  94.     {return ir_##name##_(&f);}
  95.  
  96. #define _FM_V_FP(name)    \
  97.     static void r_##name(FLT f, FLT g[])\
  98.     {r_##name##_(&f,g,g+1);}
  99.  
  100. #else
  101. /* WITHOUT single-precision library */
  102.  
  103. #define _FM_F(name)    static FLT r_##name() {return name##();}
  104. #define _FM_F_I(name)    static FLT r_##name(INT i) {return name##(i);}
  105. #define _FM_F_F(name)    static FLT r_##name(FLT f) {return name##(f);}
  106. #define _FM_F_FF(name)    static FLT r_##name(FLT f,FLT g) {return name##(f,g);}
  107. #define _FM_F_FI(name)    static FLT r_##name(FLT f,INT i) {return name##(f,i);}
  108. #define _FM_F_IF(name)    static FLT r_##name(INT i,FLT f) {return name##(i,f);}
  109. #define _FM_B_F(name)    static BOOL ir_##name(FLT f) {return ir_##name##(f);}
  110. #define _FM_I_F(name)    static INT ir_##name(FLT f) {return ir_##name##(f);}
  111. #define _FM_V_FP(name)    static void r_##name(FLT f, FLT g[])\
  112.             {double a,b; sincos(f,&a,&b); g[0]=a; g[1]=b;}
  113.  
  114. #endif
  115.  
  116. /* Nothing should go behind this #endif */
  117. #endif
  118.